﻿using System;
using System.Reflection;
using log4net;

namespace CarolLib
{
    public class Log
    {

        public static void Info(string message)
        {
            log4net.ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            log.Info(message);
        }

        public static void Info(string msgFormat, params object[] args)
        {
            string msg = string.Format(msgFormat, args);
            Info(msg);
        }

        public static void Warning(string message)
        {
            log4net.ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            log.Warn(message);
        }

        public static void Warning(string msgFormat, params object[] args)
        {
            string msg = string.Format(msgFormat, args);
            Warning(msg);
        }

        public static void Error(string message)
        {
            log4net.ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            log.Error(message);
        }

        public static void Error(string msgFormat, params object[] args)
        {
            string msg = string.Format(msgFormat, args);
            Error(msg);
        }

        public static void Exception(string message, Exception exception)
        {
            log4net.ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            log.Error(message, exception);
        }

        public static void Exception(Exception exception, string msgFormat, params object[] args)
        {
            string msg = string.Format(msgFormat, args);
            Exception(msg, exception);
        }

        /// <summary>
        /// Log Exception
        /// </summary>
        /// <remarks>overload by Lance 2009-8-19</remarks>
        /// <param name="exception">exception to log.</param>
        public static void Exception(Exception exception)
        {
            Exception(exception.Message, exception);
        }
    }
}
